dcmotor31 2.2.1
Loading...
Searching...
No Matches
dcmotor31.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2026 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef DCMOTOR31_H
29#define DCMOTOR31_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
58
63
68
73#define DCMOTOR31_REG_INPUT 0x00
74#define DCMOTOR31_REG_OUTPUT 0x01
75#define DCMOTOR31_REG_POLARITY 0x02
76#define DCMOTOR31_REG_CONFIG 0x03
77 // dcmotor31_reg
79
84
89
94#define DCMOTOR31_PIN_LO 0x01
95#define DCMOTOR31_PIN_TRQ_0 0x02
96#define DCMOTOR31_PIN_TRQ_1 0x04
97#define DCMOTOR31_PIN_TRQ_2 0x08
98#define DCMOTOR31_PIN_TRQ_3 0x10
99#define DCMOTOR31_PIN_TRQ_4 0x20
100#define DCMOTOR31_PINS_TRQ 0x3E
101
106#define DCMOTOR31_DEFAULT_CONFIG 0xC1
107
112#define DCMOTOR31_TORQUE_0 0x00
113#define DCMOTOR31_TORQUE_5 0x01
114#define DCMOTOR31_TORQUE_10 0x02
115#define DCMOTOR31_TORQUE_15 0x03
116#define DCMOTOR31_TORQUE_20 0x04
117#define DCMOTOR31_TORQUE_24 0x05
118#define DCMOTOR31_TORQUE_29 0x06
119#define DCMOTOR31_TORQUE_34 0x07
120#define DCMOTOR31_TORQUE_38 0x08
121#define DCMOTOR31_TORQUE_43 0x09
122#define DCMOTOR31_TORQUE_47 0x0A
123#define DCMOTOR31_TORQUE_51 0x0B
124#define DCMOTOR31_TORQUE_56 0x0C
125#define DCMOTOR31_TORQUE_60 0x0D
126#define DCMOTOR31_TORQUE_63 0x0E
127#define DCMOTOR31_TORQUE_67 0x0F
128#define DCMOTOR31_TORQUE_71 0x10
129#define DCMOTOR31_TORQUE_74 0x11
130#define DCMOTOR31_TORQUE_77 0x12
131#define DCMOTOR31_TORQUE_80 0x13
132#define DCMOTOR31_TORQUE_83 0x14
133#define DCMOTOR31_TORQUE_86 0x15
134#define DCMOTOR31_TORQUE_88 0x16
135#define DCMOTOR31_TORQUE_90 0x17
136#define DCMOTOR31_TORQUE_92 0x18
137#define DCMOTOR31_TORQUE_94 0x19
138#define DCMOTOR31_TORQUE_96 0x1A
139#define DCMOTOR31_TORQUE_97 0x1B
140#define DCMOTOR31_TORQUE_98 0x1C
141#define DCMOTOR31_TORQUE_99 0x1D
142#define DCMOTOR31_TORQUE_100 0x1E
143
148#define DCMOTOR31_MODE_BRAKE 0
149#define DCMOTOR31_MODE_FORWARD 1
150#define DCMOTOR31_MODE_REVERSE 2
151
157#define DCMOTOR31_DEVICE_ADDRESS_A1A0_00 0x70
158#define DCMOTOR31_DEVICE_ADDRESS_A1A0_01 0x71
159#define DCMOTOR31_DEVICE_ADDRESS_A1A0_10 0x72
160#define DCMOTOR31_DEVICE_ADDRESS_A1A0_11 0x73
161 // dcmotor31_set
163
168
173
178#define DCMOTOR31_MAP_MIKROBUS( cfg, mikrobus ) \
179 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
180 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
181 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
182 cfg.sleep = MIKROBUS( mikrobus, MIKROBUS_AN ); \
183 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
184 cfg.pha = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
185 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
186 // dcmotor31_map // dcmotor31
189
194typedef struct
195{
196 // Output pins
197 digital_out_t en;
198 digital_out_t sleep;
199 digital_out_t rst;
200 digital_out_t pha;
201
202 // Input pins
203 digital_in_t int_pin;
204
205 // Modules
206 i2c_master_t i2c;
207
208 // I2C slave address
210
212
217typedef struct
218{
219 pin_name_t scl;
220 pin_name_t sda;
221
222 pin_name_t en;
223 pin_name_t sleep;
224 pin_name_t rst;
225 pin_name_t pha;
226 pin_name_t int_pin;
227
228 uint32_t i2c_speed;
229 uint8_t i2c_address;
230
232
243
249
260
275
289
303err_t dcmotor31_write_reg ( dcmotor31_t *ctx, uint8_t reg, uint8_t data_in );
304
317err_t dcmotor31_read_reg ( dcmotor31_t *ctx, uint8_t reg, uint8_t *data_out );
318
328
338
348
358
368
378
388
398
408
419err_t dcmotor31_get_lo_pin ( dcmotor31_t *ctx, uint8_t *state );
420
431err_t dcmotor31_set_torque ( dcmotor31_t *ctx, uint8_t torque );
432
442void dcmotor31_set_mode ( dcmotor31_t *ctx, uint8_t mode );
443
444#ifdef __cplusplus
445}
446#endif
447#endif // DCMOTOR31_H
448 // dcmotor31
450
451// ------------------------------------------------------------------------ END
dcmotor31_return_value_t
DC Motor 31 Click return value data.
Definition dcmotor31.h:238
@ DCMOTOR31_ERROR
Definition dcmotor31.h:240
@ DCMOTOR31_OK
Definition dcmotor31.h:239
void dcmotor31_set_mode(dcmotor31_t *ctx, uint8_t mode)
DC Motor 31 set operation mode function.
uint8_t dcmotor31_get_int_pin(dcmotor31_t *ctx)
DC Motor 31 get INT pin function.
err_t dcmotor31_default_cfg(dcmotor31_t *ctx)
DC Motor 31 default configuration function.
void dcmotor31_exit_sleep(dcmotor31_t *ctx)
DC Motor 31 exit sleep mode function.
void dcmotor31_enable_device(dcmotor31_t *ctx)
DC Motor 31 enable device function.
err_t dcmotor31_init(dcmotor31_t *ctx, dcmotor31_cfg_t *cfg)
DC Motor 31 initialization function.
void dcmotor31_enable_output(dcmotor31_t *ctx)
DC Motor 31 enable output function.
err_t dcmotor31_get_lo_pin(dcmotor31_t *ctx, uint8_t *state)
DC Motor 31 get LO pin state function.
void dcmotor31_set_reverse_dir(dcmotor31_t *ctx)
DC Motor 31 set reverse direction function.
err_t dcmotor31_write_reg(dcmotor31_t *ctx, uint8_t reg, uint8_t data_in)
DC Motor 31 write reg function.
void dcmotor31_disable_output(dcmotor31_t *ctx)
DC Motor 31 disable output function.
void dcmotor31_cfg_setup(dcmotor31_cfg_t *cfg)
DC Motor 31 configuration object setup function.
void dcmotor31_enter_sleep(dcmotor31_t *ctx)
DC Motor 31 enter sleep mode function.
err_t dcmotor31_read_reg(dcmotor31_t *ctx, uint8_t reg, uint8_t *data_out)
DC Motor 31 read reg function.
void dcmotor31_set_forward_dir(dcmotor31_t *ctx)
DC Motor 31 set forward direction function.
err_t dcmotor31_set_torque(dcmotor31_t *ctx, uint8_t torque)
DC Motor 31 set torque function.
void dcmotor31_disable_device(dcmotor31_t *ctx)
DC Motor 31 disable device function.
DC Motor 31 Click configuration object.
Definition dcmotor31.h:218
pin_name_t sleep
Definition dcmotor31.h:223
uint32_t i2c_speed
Definition dcmotor31.h:228
pin_name_t scl
Definition dcmotor31.h:219
pin_name_t en
Definition dcmotor31.h:222
pin_name_t int_pin
Definition dcmotor31.h:226
pin_name_t sda
Definition dcmotor31.h:220
pin_name_t rst
Definition dcmotor31.h:224
pin_name_t pha
Definition dcmotor31.h:225
uint8_t i2c_address
Definition dcmotor31.h:229
DC Motor 31 Click context object.
Definition dcmotor31.h:195
digital_out_t sleep
Definition dcmotor31.h:198
digital_out_t pha
Definition dcmotor31.h:200
digital_in_t int_pin
Definition dcmotor31.h:203
i2c_master_t i2c
Definition dcmotor31.h:206
digital_out_t en
Definition dcmotor31.h:197
digital_out_t rst
Definition dcmotor31.h:199
uint8_t slave_address
Definition dcmotor31.h:209